﻿using System.Collections.Generic;
using com.guojin.core.io;
using com.guojin.core.io.message;

namespace com.guojin.mj.net.message.login
{
    //创建房间
    public class CreateRoomReq : Message
    {
        public static int TYPE =  7;
        public static int ID = 0; 

        public List<OptionEntry> options { get; set; }

        public void decode(Input _in)
        {
            var optionsLen = _in.readInt();

            if (optionsLen == -1)
                options = null;
            else
                for (var optionsI = 0; optionsI < optionsLen; optionsI++)
                {
                    var optionsItem = new OptionEntry();

                    optionsItem.decode(_in);
                    options[optionsI] = optionsItem;
                }
        }

        public void encode(Output _out)
        {
            if (options == null)
            {
                _out.writeInt(-1);
            }
            else
            {
                var optionsLen = options.Count;
                _out.writeInt(optionsLen);
                for (var optionsI = 0; optionsI < optionsLen; optionsI++)
                    options[optionsI].encode(_out);
            }
        }

        public int getMessageId()
        {
            return ID;
        }

        public int getMessageType()
        {
            return TYPE;
        }

        public string toString()
        {
            return "CreateRoomReq [ options=" + options + ", ]";
        }

        public static CreateRoomReq create( List<OptionEntry> options)
        {
            var createRoomReq = new CreateRoomReq();
            createRoomReq.options = options;
            return createRoomReq;
        }
    }
}